
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from plyer import notification

class MonitorFile(FileSystemEventHandler):
    def on_created(self, event):
        if not event.is_directory:
            self.send_notification(f"新增文件: {event.src_path}")
    
    def on_modified(self, event):
        if not event.is_directory:
            self.send_notification(f"文件修改: {event.src_path}")
    
    def on_deleted(self, event):
        if not event.is_directory:
            self.send_notification(f"文件删除: {event.src_path}")
    
    def send_notification(self, message):
        notification.notify(
            title="文件中转站监控",
            message=message,
            app_name="Folder Monitor",
            timeout=1000
        )

def start_monitoring(path='.'):
    event_handler = MonitorFile()
    observer = Observer()
    observer.schedule(event_handler, path, recursive=True)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()

if __name__ == "__main__":
    start_monitoring("/home/zqkjj/Desktop/文件中转")  # 替换为实际监控路径
